 <?php
	$public_application = $this->config->item('public_application');
 ?>
 <?php
	$font = "";
	if($fonts){
		foreach ($fonts as $key=>$value) {
			$font .= "<option value='$key'>".$value."</option>";
		}
	}
	
	
	$font_size = "";
	if( $fontSize ){
		foreach( $fontSize as $s){
			$font_size .= "<option value='$s'>".$s."</option>";
		}
	}
 ?>

<div class="main-bg clearfix">
  <div class="container main-box clearfix">
  
    <div class="row">
	<?php 
		if($ecard):	
	?>
      <div class="col-md-4 col-sm-4 hidden-xs"> 
        <div class="clearfix">
            <a href="<?php echo site_url('ecard/index');?>" class="pull-right" style="margin-right:12px;"><img src="<?php echo base_url($public_application."images/changemb.jpg")?>" class="img-responsive" /></a>
	        <img src="<?php echo base_url($ecard['thumb']);?>" class="img-responsive pull-right mt-1em" />
        </div>
      </div>
      <div class="col-md-8 col-sm-8 col-xs-12">
		<?php
		   $attributes = array('class' => 'form-horizontal mt-1em', 'role' => 'form','id'=>'form_makeEcard','name'=>'form_makeEcard');
			echo form_open_multipart(site_url('ecard/createAction'),$attributes);
		?>
			<input type="hidden" name="master" value="<?php echo $ecard['master'];?>">
			<?php
				
				//所有属性
				foreach($attrs as $key => $attr){
				
					//type == 0是文本类型
					if($attr['type'] == 0){
			?>
				<div class="form-group">
					<label  class="col-sm-2 control-label"><?php echo $attr['attr']?>:</label>
					<div class="col-md-5 col-sm-8">
					  <input type="text"  name='attr[]'  id="<?php echo $attr['id']?>" rangelength="1,<?php echo $attr['size']?>" class="form-control input-lg"  style="margin-bottom:0.5em;margin-top:5px;display:inline;" placeholder="<?php echo $attr['tips'];?>"  required/>
					<!--<select name="font[]"><?php echo $font;?></select>
						<select name="fontSize[]"><?php echo $font_size;?></select>
						<input name="fontColor[]" value="#000000"  type="text" class="input_cxcolor" readonly/>-->
						<!--<div class="auxiliary-text">限制1-<?php echo $attr['size']?>个字</div>-->
					</div>
				</div>
			<?php
					}
					else if($attr['type'] == 1){
					//type == 1是多行文本
			?>
			  <div class="form-group">
			    <label  class="col-sm-2 control-label"><?php echo $attr['attr']?>:</label>
			    <div class="col-md-5 col-sm-8">
			      <textarea name='attr[]' rangelength="1,<?php echo $attr['size']?>" id="<?php echo $attr['id']?>" class="form-control input-lg" rows="3"  style="margin-bottom:0.5em;" placeholder="<?php echo $attr['tips'];?>" required></textarea>
			    <!--<select name="font[]"><?php echo $font;?></select>
						<select name="fontSize[]"><?php echo $font_size;?></select>
						<input name="fontColor[]" value="#000000"  type="text" class="input_cxcolor" readonly/>-->
						<!--<div class="auxiliary-text">限制1-<?php echo $attr['size']?>个字</div>-->
				</div>
			  </div>
			<?php
					}
							
					/*type == 2 是图像属性
					* 图像类型则增加相应的，file类型节点类型
					*/	
					elseif($attr['type'] == 2){
			?>
			  <div class="form-group">
			    <label  class="col-sm-2 control-label"><?php echo $attr['attr']?>:</label>
			    <div class="col-md-5 col-sm-8">
					<input type="file" name='image_<?php echo $key;?>' id="<?php echo $attr['id']?>" style="margin-top:5px;" filetype="image/png"  class="custom-file-input" accept="image/png"  required />
					<div class="auxiliary-text">png格式图片 最大宽:<?php $size = explode("|",$attr['size']); echo $size[0];?>,最大高:<?php echo $size[1]?></div>
					<!--<select style="display:none;" name="font[]"><option></option></select>
					<select  style="display:none;"  name="fontSize[]"><option></option></select>
					<input name="fontColor[]" value="#000000"  type="text" class="input_cxcolor" readonly style="display:none;"/>-->
				
			    </div>
			  </div>
			<?php
					}
					/*type == 3 是图像或文字属性
					* 图像类型则增加相应的file节点
					*/
					elseif($attr['type'] == 3){
					$size = explode("|",$attr['size']); 
			?>
			  <div class="form-group">
			    <label class="col-sm-2 control-label"><?php echo $attr['attr']?>:</label>
			    <div class="col-md-5 col-sm-8">
					<input type="text"  name="attr[]" rangelength="0,<?php echo $size[2]?>" id="text<?php echo $attr['id']?>" class="form-control input-lg" placeholder="<?php echo $attr['tips']?>" depends="return $('#image<?php echo $attr['id']?>').is(':checked')"/>
					<!--<select name="font[]"><?php echo $font;?></select>
					<select name="fontSize[]"><?php echo $font_size;?></select>
					<input name="fontColor[]" value="#000000"  type="text" class="input_cxcolor" readonly />-->
					<!--<div class="auxiliary-text">文字限制<?php echo $size[2]?>个字</div>-->

					
					
			    </div>
			  </div>
			  
			  <div class="form-group">
				<label class="col-sm-2 control-label"></label>
				  <div class="col-md-5 col-sm-8">
				  <span style="color:#999;">或者上传图片</span>
				  
					<div class="clearfix" style="margin-bottom:0.5em;"></div>
					<input type="file" name='image_<?php echo $key;?>' id="image<?php echo $attr['id']?>" style="margin-top:1em;"  class="custom-file-input textimage" depends="return if($('#text<?php echo $attr['id']?>').val() !='')" accept="image/png" />
					<div class="auxiliary-text">png格式图片 最大宽:<?php echo $size[0];?>,最大高:<?php echo $size[1]?></div>
				  </div>
			  </div>
			
			<?php			
					}
			?>
					<div class="form-group">
				   <input type="hidden" name='attrid[]' value="<?php echo $attr['id']?>"/>
				   <input type="hidden" name='attrtype[]' value="<?php echo $attr['type']?>"/>
				   <input type="hidden" name='coordinate[]' value="<?php echo $attr['coordinate']?>"/>
				   <input type="hidden" name='size[]' value="<?php echo $attr['size']?>"/>
				   <input type="hidden" name='attrname[]' value="<?php echo $attr['attr']?>"/>
				   
				   </div>
			<?php
				}
			?>
			
			 
	
			  <div class="form-group clearfix">
			    <div class="col-sm-offset-2 col-sm-12 clearfix btn10-box">
			      <button class="btn btn-danger col-xs-12 col-sm-2" id="Preview" data-loading-text="生成预览中...">预览品牌书</button>
			      <button type="submit" id="Submit" class="btn btn-danger col-xs-12 col-sm-2">生成品牌书</button>
			      <button type="reset" class="btn btn-default col-xs-12 col-sm-2">重置信息</button>
			    </div>
			  </div>
		 <?php echo form_close();?>
      </div>
	  <?php endif;?>
    </div>
  </div>
</div>
<link rel="stylesheet" href="<?php echo base_url($this->config->item('public'))?>/assets/js/jquery.cxcolor/css/jquery.cxcolor.css">
<script src="<?php echo base_url($this->config->item('public'))?>/assets/js/jquery.cxcolor/js/jquery.cxcolor.min.js"></script>
<script src="<?php echo base_url($this->config->item('public'))?>/assets/js/jquery.form.js"></script>
<script src="<?php echo base_url($this->config->item('public'))?>/assets/js/jquery-validation/jquery.validate.min.js"></script>
<script src="<?php echo base_url($this->config->item('public'))?>/assets/js/jquery-validation/additional-methods.js"></script>
<script src="<?php echo base_url($this->config->item('public'))?>/assets/js/artDialog/jquery.artDialog.js?skin=zopo"></script>
<script>
	$(function (){
	
		//form 
		var form = $("#form_makeEcard");
		
//==============预览		
		var options = {
			url:"<?php echo site_url('ecard/createPreview')?>",
			dataType:'json',
			beforeSubmit:function (){
				return true;
			},
			success:function (json){
				if(sys_login(json.error)){return ;}
				if(json.error != 0){
						$.dialog({
							id:'preview#Error',
							content:json.error,
							icon:'error',
							lock:true,
							esc:false
						});
						return false;
					}else{
						img2clear =  json.result_image;
						var previewssuccess = $.dialog({
							id:'previews#success',
							title:'设计预览(关闭后继续)',
							content:"<div><img src='<?php echo base_url();?>"+json.image+"'></div>",
							lock:true,
							esc:false,
							cancel:function (){
								$.ajax({
									type: 'POST',
									url:"<?php echo site_url('ecard/clearImage/')?>",
									data:"img="+img2clear
								});
							},
							cancelVal:"关闭并继续"
						});
						
						art.list['previewssuccess'].position();
						
					}
			}
		};
		
		$("#Preview").click(function (){
			
			form.ajaxForm();
			
			form.ajaxSubmit(options);
			return false;
		});

//==============创建
		var Submitoptions = {
			url:"<?php echo site_url('ecard/createAction')?>",
			dataType:'json',
			beforeSubmit:function (){
				form.validate();
				return form.valid();
			},
			success:function (json){
				if(sys_login(json.error)){return ;}
				if(json.error != 0){
					$.dialog({
						id:'ex#Error',
						content:json.error,
						icon:'error',
						lock:true,
						esc:false
					});
					return false;
				}else{
					window.location.href = "<?php echo site_url('ecard/confirm');?>"+"/"+json.ecard_id;
					$.dialog({
						id:'ex#success',
						content:'成功',
						esc:false
					});
					form.resetForm();
				}
			},
			resetForm:false
		};
		$("#Submit").click(function (){

			form.ajaxForm();
					
			form.ajaxSubmit(Submitoptions);
			return false;
		
		});
		
		//调色板
		$("input[name='fontColor[]']").each(function(index){
			$(this).cxColor({color:$(this).val()});
			
			$(this).bind('change',function(){
		
			color = $(this).val();
			
			$(this).prevAll("[name='attr[]']").css('color',color);
			});
			
		});
		
		//字型

		//字号

		$.validator.setDefaults({
		  debug: true,
		  success: "valid",
		  errorPlacement: function(error, element) {
			    error_box = $('<div class="col-md-5 col-sm-5 "> </div>');
			    error_box.append(error);
			     
				 if(element.hasClass('textimage'))
				 error_box.appendTo(element.parent().parent().parent());
				 else if(element.attr('type') == 'file')
			      error_box.appendTo(element.parent().parent().parent());
			    else
			      error_box.appendTo(element.parent().parent());
		 }
		});

		
	});



</script>

<script>

</script>


<script src="<?php echo base_url($this->config->item('public')."/assets/js/bootstrap-file-input-master/js/bootstrap.file-input.js")?>"></script>
<link href="<?php echo base_url($this->config->item('public')."/assets/js/bootstrap-file-input-master/css/bootstrap.file-input.css")?>" rel="stylesheet">